# -*- coding = utf-8 -*-
# @Time : 2021/4/30 16:05
# @Author : 龙王赘婿_彪少
# @File : demo02.py
# @Software: PyCharm

#定义一个空列表
'''
namelist = []

namelist2 = ["小刘","小李","小张"]
print(namelist2[1])

namelist3 = [1,"小刘"]

#遍历
for i in namelist2:
    print(i)

print(len(namelist2))

j = 0
while j < len(namelist3):
    print(namelist3[j])
    j+=1
'''
#增删改查
testlist = ["一个", 2, 3.14, "bitch"]
for i in testlist:
    print(i,end=" ")
print("")

testlist.append("hii")
for i in testlist:
    print(i,end=" ")
print("")

#增加与扩展
a = [1,2]
b = [3,4]
a.append(b)
print(a)

a.extend(b)
print(a)

a.insert(2,"插入")
print(a)

#删
moviename = ["海盗","海盗","船长","宝藏","鲨鱼","贝壳"]
print(moviename)
del moviename[3]
print(moviename)
moviename.pop() #弹出最后一个元素
print(moviename)
moviename.remove("海盗") #只删第一个
print(moviename)

#改
change = ["海盗","海盗","船长","宝藏","鲨鱼","贝壳"]
print(change)
change[1] = "水手"
print(change)

#查 in    和    not in
find = "歌手"
if find in change:
    print("找到了")
else:
    print("没")

mylist = ["a","b","c","a","b"]

print(mylist.index("a",2,4)) #查找返回下标
#左闭右开
#找不到就报错

print(mylist.count("b")) #统计一下元素个数

#    反转   排序
listnum = ["2","4","3","7","1","5"]
print(listnum)
listnum.reverse()
print(listnum)
listnum.sort()
print(listnum)
listnum.sort(reverse=True)
print(listnum)

schoolNames = [ ["北京大学","清华大学"],["北科大","云大","科技大"],["师大","石油大"] ]
#有三个元素的空列表，每个元素都是空列表
print(schoolNames[1][0])

